package Form;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.SystemColor;
import java.awt.Toolkit;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

import Control.Shop_Product_Controller;

public class Shop_Product_Form extends JPanel{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -4267213787856135881L;
	
	private JLabel lblCatalog;
	private JScrollPane catalogsHolder;
	private JPanel catalogs;
	private JScrollPane productsHolder;
	private JPanel products;
	private JPanel details;
	private JLabel lblCatalogname;
	
	//Object Attributes
	private Main parser;
	private Shop_Product_Controller control;
	private JPanel panel;
	private JLabel backgroundImage;
	
	//Getter and Setter for object 
	public Main getParser() {
		return parser;
	}

	public void setParser(Main parser) {
		this.parser = parser;
	}

	public Shop_Product_Controller getControl() {
		return control;
	}

	public void setControl(Shop_Product_Controller control) {
		this.control = control;
	}

	public Shop_Product_Form(Main parser){
		this.setParser(parser);
		this.control = new Shop_Product_Controller(this);
		
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{160, 281, 0};
		gridBagLayout.rowHeights = new int[]{56, 262, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		GridBagConstraints gbc_lblCatalog = new GridBagConstraints();
		gbc_lblCatalog.fill = GridBagConstraints.BOTH;
		gbc_lblCatalog.insets = new Insets(0, 0, 5, 5);
		gbc_lblCatalog.gridx = 0;
		gbc_lblCatalog.gridy = 0;
		add(getLblCatalog(), gbc_lblCatalog);
		GridBagConstraints gbc_details = new GridBagConstraints();
		gbc_details.fill = GridBagConstraints.BOTH;
		gbc_details.gridx = 1;
		gbc_details.gridy = 0;
		add(getDetails(), gbc_details);
		GridBagConstraints gbc_catalogsHolder = new GridBagConstraints();
		gbc_catalogsHolder.insets = new Insets(0, 0, 0, 5);
		gbc_catalogsHolder.fill = GridBagConstraints.BOTH;
		gbc_catalogsHolder.gridx = 0;
		gbc_catalogsHolder.gridy = 1;
		add(getCatalogsHolder(), gbc_catalogsHolder);
		getPanel().setLayout(null);
		GridBagConstraints gbc_panel = new GridBagConstraints();
		gbc_panel.fill = GridBagConstraints.BOTH;
		gbc_panel.gridx = 1;
		gbc_panel.gridy = 1;
		add(getPanel(), gbc_panel);
	}

	public JLabel getLblCatalog() {
		if (lblCatalog == null) {
			lblCatalog = new JLabel("Categories");
			lblCatalog.setHorizontalAlignment(SwingConstants.CENTER);
			lblCatalog.setFont(new Font("Tahoma", Font.PLAIN, 31));
		}
		return lblCatalog;
	}
	public JScrollPane getCatalogsHolder() {
		if (catalogsHolder == null) {
			catalogsHolder = new JScrollPane();
			catalogsHolder.setPreferredSize(new Dimension(150, 500));
			catalogsHolder.setBorder(null);
			catalogsHolder.setViewportView(getCatalogs());
		}
		return catalogsHolder;
	}
	public JPanel getCatalogs() {
		if (catalogs == null) {
			catalogs = new JPanel();
		}
		return catalogs;
	}
	public JScrollPane getProductsHolder() {
		if (productsHolder == null) {
			productsHolder = new JScrollPane();
			productsHolder.setBounds(0, 0, 435, 515);
			productsHolder.setBorder(null);
			productsHolder.setPreferredSize(new Dimension(600, 500));
			productsHolder.setViewportView(getProducts());
			productsHolder.setOpaque(false);
			productsHolder.getViewport().setOpaque(false);
		}
		return productsHolder;
	}
	public JPanel getProducts() {
		if (products == null) {
			products = new JPanel();
			products.setOpaque(false);
			FlowLayout flowLayout = (FlowLayout) products.getLayout();
			flowLayout.setAlignment(FlowLayout.LEFT);
			products.setBorder(new LineBorder(Color.decode("#002640"), 5));
			products.setBackground(SystemColor.desktop);
		}
		return products;
	}
	public JPanel getDetails() {
		if (details == null) {
			details = new JPanel();
			details.setBackground(Color.decode("#002640"));
			details.setLayout(new GridLayout(1, 2, 0, 0));
			details.add(getLblCatalogname());
		}
		return details;
	}
	public JLabel getLblCatalogname() {
		if (lblCatalogname == null) {
			lblCatalogname = new JLabel("Select a category to view");
			lblCatalogname.setHorizontalAlignment(SwingConstants.CENTER);
			lblCatalogname.setForeground(Color.WHITE);
			lblCatalogname.setFont(new Font("Tahoma", Font.BOLD, 19));
		}
		return lblCatalogname;
	}
	public JPanel getPanel() {
		if (panel == null) {
			panel = new JPanel();
			panel.add(getProductsHolder());
			panel.add(getBackgroundImage());
		}
		return panel;
	}
	public JLabel getBackgroundImage() {
		if (backgroundImage == null) {
			backgroundImage = new JLabel("");
			backgroundImage.setOpaque(true);
			backgroundImage.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage("Resources/Images/Backgrounds/orange_checkered.png").getScaledInstance(475, 533, Image.SCALE_DEFAULT)));
			backgroundImage.setBounds(0, 0, 435, 515);
		}
		return backgroundImage;
	}
}
